package com.cmc.cloud.cmclink.doc.controller.admin.so;

import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.service.so.SoSplitCombineService;
import com.cmc.cloud.cmclink.doc.vo.sovo.sosplitcombinedetailvo.*;
import com.cmc.cloud.cmclink.doc.vo.sovo.sovo.SoDetailRespVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import com.cmes.framework.security.core.util.SecurityFrameworkUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


/**
 * 订舱拆分合并记录表  前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 订舱拆分合并记录表  ")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/so-split-combine")
public class SoSplitCombineController {
    @Resource
    private SoSplitCombineService soSplitCombineService;

    @Operation(summary = "获得订舱详细为了拆分")
    @GetMapping("/getSoDetailForSplit/{soId}")
    @Parameter(name = "soId", description = "soId", required = true, example = "123")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:shipment:split')")
    public CommonResult<SoDetailRespVO> getSoDetailForSplitAndCombine(@PathVariable("soId") Long soId) {
        return CommonResult.success(soSplitCombineService.getSoDetailForSplitAndCombine(soId));
    }

    @Operation(summary = "获得订舱详情多个列表为了合并")
    @PostMapping("/getSoDetailListForCombine")
    @PreAuthorize("@ss.hasPermission('doc:shipment:combine')")
    public CommonResult<List<SoDetailRespVO>> getSoDetailListForSplitAndCombine(@RequestBody List<Long> soIds) {
        return CommonResult.success(soSplitCombineService.getSoDetailListForSplitAndCombine(soIds));
    }

    @Operation(summary = "创建订舱拆分")
    @PostMapping("/createSoSplit")
    @PreAuthorize("@ss.hasPermission('doc:shipment:split')")
    public CommonResult<Long> createSoSplit(@Valid @RequestBody SoSplitCreateReqVO createReqVO) {
        soSplitCombineService.createSoSplit(createReqVO, String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
        return CommonResult.success();
    }

    @Operation(summary = "创建订舱合并")
    @PostMapping("/createSoCombine")
    @PreAuthorize("@ss.hasPermission('doc:shipment:combine')")
    public CommonResult<Long> createSoCombine(@Valid @RequestBody SoCombineCreateReqVO updateReqVO) {
        soSplitCombineService.createSoCombine(updateReqVO, String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
        return CommonResult.success();
    }

    @Operation(summary = "获得订舱拆分合并详情")
    @GetMapping("/getSoSplitCombineDetail/{splitCombineId}")
    @Parameter(name = "splitCombineId", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('doc:soSplitCombine:preview')")
    public CommonResult<SoSplitCombineAllRespVO> getSoSplitCombineDetail(@PathVariable("splitCombineId") Long splitCombineId) {
        SoSplitCombineAllRespVO soSplitCombine = soSplitCombineService.getSoSplitCombine(splitCombineId);
        return CommonResult.success(soSplitCombine);
    }

    @Operation(summary = "获得订舱拆分合并记录表  分页")
    @PostMapping("/getSoSplitCombinePage")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:soSplitCombine:search')")
    public CommonResult<PageResult<SoSplitCombinePageRespVO>> getSoSplitCombinePage(@RequestBody SoSplitCombinePageReqVO pageVO) {
        return CommonResult.success(soSplitCombineService.getSoSplitCombinePage(pageVO));
    }
}
